package com.demo.pattern.singleton;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2022-05-22 12:56
 * @Description: SingletonDemo$
 */
public class SingletonDemo {
	public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
		/*System.out.println(StarvingSingleton.getInstance());
		System.out.println(StarvingSingleton.getInstance());

		//Class clazz = StarvingSingleton.class;
		Class clazz = LazyDoubleCheckSingleton.class;

		Constructor constructor = clazz.getDeclaredConstructor();
		constructor.setAccessible(true);
		System.out.println(constructor.newInstance());*/

		System.out.println(EnumStarvingSingleton.getInstance());
		Class clazz = EnumStarvingSingleton.class;
		Constructor constructor = clazz.getDeclaredConstructor();
		constructor.setAccessible(true);
		EnumStarvingSingleton enumStarvingSingleton = (EnumStarvingSingleton)constructor.newInstance();
		System.out.println(enumStarvingSingleton.getInstance());

	}
}
